package com.echat.messagesender.sender.controller;

import com.echat.commonlib.bean.HttpResult;
import com.echat.messagesender.sender.bean.EchatSendEmailInfo;
import com.echat.messagesender.sender.bean.EchatSendSmsInfo;
import com.echat.messagesender.sender.constant.Constants;
import com.echat.messagesender.sender.service.EchatEmailSendService;
import com.echat.messagesender.sender.service.EchatSmsSendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chenmohan on 2018/08/31
 *
 * @description
 */
@RestController
public class SendController {

    @Autowired
    EchatEmailSendService emailSendService;

    @Autowired
    EchatSmsSendService smsSendService;

    /**
     * 发送邮件
     * @param info
     * @return
     */
    @RequestMapping("/email")
    public HttpResult sendEmail(EchatSendEmailInfo info){
        if(emailSendService.sendEmail(info)){
            return HttpResult.success("send email success" , Constants.DO_IS_OK);
        }else{
            return HttpResult.success("send email failed" , Constants.DO_IS_FAILED);
        }
    }

    /**
     * 发送短信
     * @param info
     * @return
     */
    @RequestMapping("/sms")
    public HttpResult sendSms(EchatSendSmsInfo info){
        if(smsSendService.sendSMS(info)){
            return HttpResult.success("send SMS success" , Constants.DO_IS_OK);
        }else{
            return HttpResult.success("send SMS failed" , Constants.DO_IS_FAILED);
        }
    }

    @RequestMapping("/test")
    public HttpResult test(){
        return HttpResult.success("这是SendController权限测试接口,看到这条信息表示认证成功");
    }


}
